package com.zishi.venuesbooking.ac;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zishi.venuesbooking.BaseActivity;
import com.zishi.venuesbooking.R;
import com.zishi.venuesbooking.adapter.CommentAdapter;
import com.zishi.venuesbooking.adapter.ReserveAdapter;
import com.zishi.venuesbooking.entity.Comment;
import com.zishi.venuesbooking.entity.Reserve;

import org.json.JSONException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ReserveActivity extends BaseActivity {

    private RecyclerView rvReserves;
    private ReserveAdapter adapter;
    private List<Reserve> reserves = new ArrayList<>();
    private Button btnBack;
    private TextView tvFriendName;
    @Override
    protected int initLayout() {
        return R.layout.activity_reserve;
    }

    @Override
    protected void initView() {

        rvReserves = findViewById(R.id.all_reserve_list);
        btnBack = findViewById(R.id.advice_back_btn);
        tvFriendName = findViewById(R.id.friend_name);

        // 设置评论列表
        adapter = new ReserveAdapter(reserves);
        rvReserves.setLayoutManager(new LinearLayoutManager(this));
        rvReserves.setAdapter(adapter);

    }

    @Override
    protected void initData() throws JSONException, IOException {
        loadReserves();
        initListener();
    }

    protected void initListener() {
        // 返回按钮点击事件
        btnBack.setOnClickListener(v -> finish());
        // 点击用户名跳转到用户信息页面
        tvFriendName.setOnClickListener(v -> {
            // TODO: 跳转到用户信息页面
            navigateToWithSlowAnimation(MyInfoActivity.class);
        });
    }
    private void loadReserves() {
        // 模拟数据加载
        List<Reserve> reserves = new ArrayList<>();
        reserves.add(new Reserve("1",  "file:///android_asset/images/venue/venue_avata_1.png",
                "venue1", "outdoor football playground", "这个场馆很不错，设施齐全", "8km", "8/10"
        ));
        reserves.add(new Reserve("2",  "file:///android_asset/images/venue/venue_avata_2.png",
                "venue2", "indoor badminton venue", "这个场馆很不错，设施齐全", "8km", "7/10"
        ));

        adapter.updateData(reserves);
        // 从网络或数据库加载评论数据
        // comments.addAll(...);
        // adapter.notifyDataSetChanged();
    }
}